package com.lanchetech.merchant.controller;

import com.lanchetech.bean.response.ContentUploadPictureResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.AreaVO;
import com.lanchetech.entity.LogisticsCompany;
import com.lanchetech.service.AreaService;
import com.lanchetech.service.FileService;
import com.lanchetech.service.LogisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(value = "通用接口", tags = "例如文件上传等")
@RequestMapping("/api/common")
@RestController
public class CommonController {

    @Autowired
    FileService fileService;

    @Autowired
    AreaService areaService;

    @Autowired
    LogisticsService logisticsService;

    @ApiOperation("上传文件，包括图片等")
    @PostMapping("/uploadFile")
    public ResultData<String> uploadFile(@RequestParam("file") MultipartFile file,
                                         @RequestParam(value = "oldImage", required = false, defaultValue = "") String oldImage) {
        return fileService.uploadFile(file, oldImage);
    }

    @ApiOperation("上传富文本图片")
    @PostMapping("/updateContentPicture")
    public ContentUploadPictureResp updateContentPicture(@RequestParam("file") MultipartFile file) {
        return fileService.updateContentPicture(file);
    }

    @ApiOperation("获取省市区街道列表")
    @GetMapping("/getAreaList")
    public ResultData<List<AreaVO>> getAreaList(@RequestParam("level") Integer level, @RequestParam(value = "pid", required = false) Long pid) {
        return areaService.getAreaList(level, pid);
    }

    @ApiOperation("获取所有快递公司列表")
    @GetMapping("/getLogisticsCompanyList")
    public ResultData<List<LogisticsCompany>> getLogisticsCompanyList() {
        return logisticsService.getLogisticsCompanyList();
    }
}
